
/**
 * 虚引用测试，随时都有可能会被删除，删除该对象的时候会调用  finalize() 方法
 *
 * @author: zyc
 */
public class SoftReferenceTest2 {

    private String flag = "";

    public static void main(String[] args) {
        get();
        int i = 0;
        while (true) {
            System.out.println("创建对象" + (++i));
            new Object();
        }
    }

    private static void get() {
        new SoftReferenceTest2().flag = "虚引用测试";
    }


    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("flag=" + flag);
    }
}
